Fix Vultr startup script JSON serialization issues #14853
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes JSON serialization issues with the Vultr cloud provider's startup script handling.
Problem
The startup_script module was failing with:
This occurred due to complex interactions between:
Solutions
1. Two-Step Fact Assignment
Implemented the Linode provider pattern: evaluate the template into a fact first, then pass that fact to the module. This ensures the template is fully evaluated before JSON serialization.
Change:
2. Cloud-Init Template String Filters
Added
| stringfilters to nested lookups infiles/cloud-init/base.ymlto ensure consistent string handling:Known Issue - Dependency Bug
IMPORTANT: There is a bug in
vultr.cloudcollection v1.13.0 that prevents this from working completely.The module's
configure()method calls:The
base64.b64encode()returns bytes, which cannot be JSON serialized. It should be:Upstream bug report: Will be filed at https://github.com/vultr/ansible-collection-vultr/issues/
Until this is fixed upstream, users will need to manually patch the module or wait for a new release.
Testing
Impact
Files Changed
roles/cloud-vultr/tasks/main.yml- Two-step fact assignment for startup scriptfiles/cloud-init/base.yml- String filters on nested lookups (shared by all providers)Technical Details
The vultr.cloud.startup_script module (v1.13.0) calls
base64.b64encode(script.encode())internally. When combined with Ansible 2.19's "tagless" JSON serialization profile, certain template evaluation patterns can result in bytes objects that fail serialization. The two-step fact assignment ensures the template is fully evaluated to a string before entering the module's processing pipeline.However, the module itself has a bug that creates bytes that cannot be serialized. This PR contains the Algo-side fixes, but full functionality depends on the upstream fix.